/**
 * Created by Dalyn on 2017/2/28.
 */
import React from "react";
import { hashHistory } from 'react-router';
import Confirm from '../../common/Confirm'
import ListOrderMutation from "./mutation/ListOrderMutation"
import Order_Item from './Order_Item'
import './css/IndentManage.css'
import Util from "../../util/Util"
import Reactkey from "../../util/ReactKey"
import "./css/ListOrder_SaleAndRe.css"
import InfoOrderMutation from "./mutation/InfoOrderMutation"
import Relay from "react-relay";
import SendGoods_Item from "./SendGoods_Item"
import SendGoodsOrderMutation from "./mutation/SendGoodsOrderMutation"
import {message} from 'antd';
/*信息列表*/
export default class GoodsRecord extends React.Component{
    constructor(props){
        super(props);
        this.state={
            orders:[]
        };
        this.enid = sessionStorage.getItem('enterpriseId');
        this.oid  = ''
    }


    componentWillMount(){
        let oid = this.props.params.oid;
        this.oid = oid;
        Relay.Store.commitUpdate(
            new InfoOrderMutation({
                orderId: oid,
                enId: this.enid,
            }),
            {
                onFailure: () => {
                },
                onSuccess: (response) => {
                    let errorCode = response.infoOrder.infoOrder.errorCode;
                    if(errorCode=='0'){
                        let order = response.infoOrder.infoOrder.order.orderGoodss;
                        this.setState({
                            orders:order,
                        });
                    }
                }
            }
        )
    }


    addDepartmenlist(){

        return this.state.orders.map((context,index)=>{
            return (
                <SendGoods_Item context={context} key={index+''} index={index} ref={'orderin'+index}/>
            );
        });
    }

    stroke(){

    }

    status(){
        return this.oArr.map((item,index)=>{
            return (
                <span style={{width:80,height:27,borderRadius:"8px",background:"#ccc",display:"block"}} onClick={this.stroke.bind(this)}>{item}</span>
            )
        })
    }

    createorder(){
        hashHistory.push('/createorder')
    }

    sendgoods(){
        let goodinfo = [];
        this.state.orders.map((item,index)=>{
            let info  = this.refs['orderin'+index].context;
            if(!this.refs['orderin'+index].state.text==''){
                goodinfo.push(info);
            }
        });
        let gi = JSON.stringify(goodinfo);
        Relay.Store.commitUpdate(
            new SendGoodsOrderMutation({
                orderId:this.oid,
                goodsInfo:gi,
            }),
            {
                onFailure: () => {
                },
                onSuccess: (response) => {
                    let errorCode = response.sendGoodsOrder.sendGoodsOrder.errorCode;
                    if(errorCode ==0){
                        hashHistory.push('/sendGoodsRecord/'+this.oid)
                    }else{
                        message.info('发货失败');
                    }
                }
            }
        )
    }

    onSure(size,num){
        this.queryorderlist(size,num);
    }

    render(){
        return (
            <div className="order_box" style={{width:1233,minHeight:475,background:"#f5f5f5",paddingTop:"20px"}}>
                <div style={{width:1195,minHeight:"592px",background:"#fff",marginTop:"20px",padding:"38px 19px 0 19px",position:"relative"}}>
                    <table className="order_list_saleandre_form_table">
                        <thead>
                        <tr className="order_list_saleandre_from_tr">
                            <td className="order_list_saleandre_from_td order_list_saleandre_goodrecord_time">发货时间</td>
                            <td className="order_list_saleandre_from_td order_list_saleandre_goodrecord_name">品名</td>
                            {
                              /*
                              <td className="order_list_saleandre_from_td order_list_saleandre_goodrecord_size">规格/尺码</td>
                              */
                            }
                            <td className="order_list_saleandre_from_td order_list_saleandre_goodrecord_price">单价</td>
                            <td className="order_list_saleandre_from_td order_list_saleandre_goodrecord_end">数量</td>
                            <td className="order_list_saleandre_from_td order_list_saleandre_goodrecord_end">剩余数量</td>
                            <td className="order_list_saleandre_from_td order_list_saleandre_goodrecord_end">发货数量</td>
                        </tr>
                        </thead>
                        {
                            this.addDepartmenlist()
                        }
                    </table>
                    <div className="order_list_sendgoods_divbutton" onClick={this.sendgoods.bind(this)}>发货</div>
                </div>
            </div>

        )
    }
}
